package com.syt.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.syt.cmn.mapper.DictMapper;
import com.syt.model.cmn.Dict;
import com.syt.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @Author: xxx
 * @Date: 2023/2/5 17:50
 * @Description: 导入数据监听器excel
 */
public class DictExcelListener extends AnalysisEventListener<DictEeVo> {
    
    
    
    //有参构造
    private DictMapper dictMapper;

    public DictExcelListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    @Override
    public void invoke(DictEeVo data, AnalysisContext context) {
        //调用方法添加到数据
        Dict dict = new Dict();
        BeanUtils.copyProperties(data, dict);
        int insert = dictMapper.insert(dict);
        System.out.println("insert="+insert);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
